public class Minimum_operand {
    class Solution {
        public int minOperations(int[] nums, int x) {
            int left =0;
            int right =0;
            int sum =0;
            for(int a:nums){
                sum += a;
            }
            int target = sum-x;
            if(target<0){
                return -1;
            }
            int ret = -1;
            for(int tem =0; right<nums.length;right++){
                tem += nums[right];
                while(tem>target){
                    tem-=nums[left++];
                }
                if(tem==target){
                    ret = Math.max(ret,right-left+1);
                }
            }
            if(ret==-1){
                return -1;
            }
            else{
                return nums.length-ret;
            }
        }
    }
}
